package com.partner.partnerback.common;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * 跨域配置类
 */
@Configuration
public class CorsConfig {

    @Bean
    public CorsFilter corsFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.addAllowedHeader("*"); //设置访问源头请求
        configuration.addAllowedMethod("*"); //设置访问源请求方法
        configuration.addAllowedOrigin("*"); //设置访问源地址
        configuration.setMaxAge(1800L);
        source.registerCorsConfiguration("/**", configuration); // 对接口配置跨域设置
        return new CorsFilter(source);
    }

}
